﻿var formReForm;
function doReform() {
    // load the css
    formReForm = new FormReForm('fieldForm');
    //formReForm.loadformReFormCss();

    // do the reform with default settings
    formReForm.doReForm();

}

var fnSave = function () {
    Save();
}

var trySave = function () {
    var formObject = document.getElementById('form2');
    YAHOO.util.Connect.setForm(formObject);
    var cObj = YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&action=" + action + "&entity=" + entity, callback);
}


function Save() {


    if (typeof (fnCustomSave) == "function") {
        fnCustomSave();
        return;
    }

    if (typeof (trySave) == "function") {

        GetValue();
        var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
        //var json =$.toJSON(instance[0]).replace(/'/g,"[B]").replace(/\n/g,'[BR]');
        $("#jsonDataContent").val(json);
        trySave();
        return;
    }
    if (checkInputData() == "0") {
        return;
    }

    fnSystemSave();
}


var responseSuccess = function (res) {
    try {

        var str = res.responseText;
        if (str == "1") {
            alert("数据保存成功");
            if (action == 'insert') {
                //parent.fnAddRow(instance[0]);
                parent.ReLoadData();
            } else {
                parent.ReLoadData();
                //parent.fnUpdateRow(instance[0]);
            }
            parent.closeWin();
        }
        else {
            showMessage();
            alert(str + "\n" + "数据保存失败!");
        }
    }
    catch (e) {
    }
    finally {
    }
};

var responseFailure = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback = {
    success: responseSuccess,
    failure: responseFailure
};

var SetCountrolValue = function (o) {
    $.each(o, function (property, value) {
        //try {
        value = value + "";
        // find the control and set value
        if (property != "") {
            var control = $("[name='" + property + "']");
            var strValue = value.replace(/@1@1@1/g, "'");
            strValue = strValue.replace(/@2@2@2/g, '"');
            strValue = strValue.replace(/@@@@/g, "\n");
            strValue = strValue.replace(/[BR]/g, "\n");
            control.val(strValue);
            try {
                $('#' + property).combobox('setValue', strValue);
            } catch (Error) { }
        }
    });
}

//var MaxWin = function () {
//    this.get
//}